package com.hex.ds.hdtp.core.inf.data.contrast.service;

import com.hex.ds.hdtp.core.inf.metadata.entity.TableFieldsEntity;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * @Package com.hex.ds.hdtp.core.inf.data.contrast.service
 * @ClassName IDataInfoService
 * @Description 各数据库操作接口
 * @Author gj.xu
 * @Date 2024/3/4 18:40
 * @Version v2.0
 **/
public interface IDataInfoService {

    /* 表结构对比 */
    // 是否有表
    Boolean selectTableExist(String sourceCode, String schema, String table) throws SQLException;

    // 字段总数
    Long selectAllFieldNum(String sourceCode, String schema, String table) throws SQLException;

    /**
     * Thread.currentThread().interrupt();
     * @param sourceCode
     * @param schema
     * @param table
     * @return
     */
    List<String> selectFieldName(String sourceCode, String schema, String table);

    // 分区字段
    List<String> selectPartitionField(String sourceCode, String schema, String table) throws SQLException;

    //编码
    String selectCoding(String sourceCode);
    /* 汇总数据对比 */
    // 数据量

    Long selectIsHaveData(String sourceCode, String schema, String table) throws SQLException;

    Long selectDataNum(String sourceCode, String schema, String table, String partitionWhereSql, String whereCondition) throws SQLException;

    // length max
    Long selectLengthMax(String sourceCode, String schema, String table, String field, String partitionWhereSql) throws SQLException;

    //字符类型Sum
    Long selectFieldLengthSum(String sourceCode, String field, String schema, String table, String partitionWhereSql) throws SQLException;

    //字符类型Sum trim
    Long selectFieldLengthSumTrim(String sourceCode, String field, String schema, String table, String partitionWhereSql) throws SQLException;

    //数值sum
    Float fieldNumberSum(String sourceCode, String field, String schema, String table, String partitionWhereSql) throws SQLException;

    // 去重count
    Long selectDistinctCount(String sourceCode, String schema, String table, String field, String whereSql) throws SQLException;

    //字段为空 count
    Long selectCountSumIsNull(String sourceCode, String schema, String table, String field, String whereSql) throws SQLException;

    // 分组count
    Long selectGroupCount(String sourceCode, String schema, String table, String field, String whereSql) throws SQLException;

    // 字段count
    List<Map<String, String>> selectFieldCount(String sourceCode, String schema, String table, String field, String whereSql) throws SQLException;

    // 字段sum
    Long selectFieldSum(String sourceCode, String schema, String table, String field, String whereSql) throws SQLException;

    // 字段trim
    List<String> selectFieldTrim(String sourceCode, String schema, String table, String field, String whereSql) throws SQLException;


    // 自定义Sql
    List<Map<String, Object>> selectCustomSql(String sourceCode, String customSql) throws SQLException;

    // 获取全字段明细对比的SQL
    String selectAllFieldSql(String sourceType, String fields, String schema, String table, String partitionsWhereSql, String sortField);

    // 分批 全字段明细对比 SQL
    String selectAllFieldSqlLimit(String type, String fields, String schema, String table, String partitionsWhereSql, Long extractScope, Long offset, String sortField);

    // 查询建表语句
    String selectCreateTableSql(String sourceCode, String schema, String table);

    // 建立建表语句
    String buildCreateTableSql(List<TableFieldsEntity> tableFieldsEntities, List<String> partitionFieldName, String isCover);

    //字段类型
    List<Map<String, String>> selectAllFieldType(String sourceCode, String schema, String table) throws SQLException;

    //字段长度
    List<Map<String, String>> selectAllFieldLength(String sourceCode, String schema, String table) throws SQLException;

    //字段精度
    List<Map<String, String>> selectFieldAccuracy(String sourceCode, String schema, String table) throws SQLException;

    /**
     * 获取字符数据类型
     *
     * @param sourceType
     * @return
     */
    List<String> getStrDataType(String sourceType);

    /**
     * 获取数值数据类型
     *
     * @param sourceType
     * @return
     */
    List<String> getNumDataType(String sourceType);

    /**
     * 获取精度数据类型
     *
     * @param sourceType
     * @return
     */
    List<String> getAccuracyDataType(String sourceType);
}
